<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>

<meta charset="utf-8" />
<link rel="icon" type="image/png"
	href="img/favicon.ico">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

<title>新闻列表</title>

<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0'
	name='viewport' />
<meta name="viewport" content="width=device-width" />


<!-- Bootstrap core CSS     -->
<link href="${pageContext.request.contextPath}/css/bootstrap.min.css"
	rel="stylesheet" />

<!-- Animation library for notifications   -->
<link href="${pageContext.request.contextPath}/css/animate.min.css"
	rel="stylesheet" />

<!--  Light Bootstrap Table core CSS    -->
<link
	href="${pageContext.request.contextPath}/css/light-bootstrap-dashboard.css"
	rel="stylesheet" />


<!--  CSS for Demo Purpose, don't include it in your project     -->
<link href="${pageContext.request.contextPath}/css/demo.css"
	rel="stylesheet" />


<!--     Fonts and icons     -->
<link
	href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css"
	rel="stylesheet">
<link href="${pageContext.request.contextPath}/css/pe-icon-7-stroke.css"
	rel="stylesheet" />
<style>
    input[type=number] {
        -moz-appearance:textfield;
    }
    input[type=number]::-webkit-inner-spin-button,
    input[type=number]::-webkit-outer-spin-button {
        -webkit-appearance: none;
        margin: 0;
    }

</style>
<!--   Core JS Files   -->
<script src="${pageContext.request.contextPath}/js/jquery-1.10.2.js"
        type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"
        type="text/javascript"></script>
<script type="text/javascript">
    $(function () {

        //批量删除
        $("#delUser").click(function () {
            var arr = [];
            $("[name='check']").each(function () {
                if($(this).prop("checked")){
                    arr.push($(this).val())
                }
            })
            $.ajax({
                url:"${pageContext.request.contextPath}/news/delNews.html",
                data:{
                    nid:arr
                },
                success:function (data) {
                    alert("删除成功！")
                    window.location.reload()
                }
            })
        })

    })
</script>
</head>
<body>

	<div class="wrapper">




        <!--左侧导航栏-->
        <%@include file="./include/left.jsp"%>
		

		<div class="main-panel">
			
       <%@include file="./include/nav.jsp"%>



			<div class="content">

				<div class="container-fluid">

					<div class="row">
					
						<div class="col-md-12">
							<div class="card">
								<div class="header">
									<h4 class="title">新闻管理</h4>
									<p class="category">Here is a subtitle for this table</p>
									
									<form action="${pageContext.request.contextPath}/news/toNews.html" method="get">
		                           <div style="float:left; margin:0 2px; width: 130px;">
		                           <select name="csid" class="form-control" style="width: 130px;">
		                           		<option value="-1">所有类别 </option>
										   <c:forEach items="${categorySeconds}" var="categorySecond">
											   <option ${categorySecond.id==myPageInfo.searchCsid?"selected":""} value="${categorySecond.id}">${categorySecond.csname} </option>
										   </c:forEach>
		                           
		                           </select>
		                           </div>
		                           <div style="float:left; margin:0 2px; width: 100px;">

		                           </div>
		                         	 
		                           <div style="float:left; margin:0 2px; width: 130px;"> 
		                            <input type="text" class="form-control" placeholder="新闻名称" size=8  name="title"  value="${myPageInfo.title}">
		                          </div>
		                          <div style="float:left; margin:0 2px; width: 65px;">
		                          <button type="submit"  class="btn btn-info btn-fill pull-right">查询</button>
		                          </div>
								<div style="float:left; margin:0 2px; width: 65px;">
									<button type="button" onclick="window.location.href='${pageContext.request.contextPath}/news/addNews.html'" class="btn btn-info btn-fill pull-right">添加</button>
		                          </div>
                          	</form>
									
								</div>
								
								
								
								
								
								
								
								
								
								
								
								<div class="content table-responsive table-full-width">
									<form action="manage/NewsAction?flag=delNews"
										method="post">

										<table class="table table-hover table-striped">
											<thead>
												<th>序号</th>
												<th>标题</th>
												<th>类别</th>
												<th>日期</th>
												<th>上传人</th>
                                                <th>操作</th>
                                                <th><button type="button" class="btn btn-info btn-fill pull-left" id="delUser">删除</button></th>
												
											</thead>
											<tbody>
												<c:forEach items="${myPageInfo.list}" var="news" varStatus="vs">

													<c:forEach items="${categorySeconds}" var="categorySecond">
														<c:if test="${news.csid==categorySecond.id}">
															<c:set var="newsType" value="${categorySecond.csname}"></c:set>
														</c:if>
													</c:forEach>
                                                    <c:set var="title" value="${news.title}"></c:set>
                                                   <c:choose>
                                                       <c:when test="${fn:length(news.title)>15}">
                                                           <c:set var="title" value="${fn:substring(news.title, 0,15 )}..."></c:set>
                                                       </c:when>
                                                   </c:choose>
													<tr>
														<td>${vs.count}</td>
														<td>${title}</td>
														<td>${newsType}</td>
														<td><fmt:formatDate value="${news.createTime}" pattern="yyyy-MM-dd HH:MM:SS"/></td>
														<td>${news.username}</td>
                                                        <td>
                                                            <button type="button" rel="tooltip" title="修改"
                                                                class="btn btn-info btn-simple btn-xs"
                                                                onclick="window.location.href='${pageContext.request.contextPath}/news/toUpdateNews.html?id=${news.id}&pageNow=${myPageInfo.pageNum}&title=${myPageInfo.title}&csid=${myPageInfo.searchCsid}'">
                                                                <i class="fa fa-edit"></i>
                                                            </button>
                                                        </td>

                                                        <td>
                                                            <label class="checkbox">
                                                            <input type="checkbox" name="check" data-toggle="checkbox" value="${news.id}">
                                                            </label>
                                                        </td>

														

													</tr>
												</c:forEach>




												<!-- <tr>
													<td>1</td>
													<td>Dakota Rice</td>
													<td>$36,738</td>
													<td>Niger</td>
													<td>Oud-Turnhout</td>
												</tr> -->
											</tbody>
										</table>
									</form>
								</div>
								<div style=" margin: 0 0 0px 50px;padding:0 0 20px 0; width: 70%;">
                                <!--分页-->
                                    <c:if test="${!myPageInfo.isFirstPage}">
                                        <a href="${pageContext.request.contextPath}/news/toNews.html?pageNow=1&title=${myPageInfo.title}&csid=${myPageInfo.searchCsid}">
                                            【首页】 </a>
                                        <a href="${pageContext.request.contextPath}/news/toNews.html?pageNow=${myPageInfo.pageNum-1}&title=${myPageInfo.title}&csid=${myPageInfo.searchCsid}">
                                            【上一页】 </a>
                                    </c:if>
                                    <c:forEach items="${myPageInfo.navigatepageNums}" var="i">
                                        <a ${i==myPageInfo.pageNum?"style='color:grey'":""} href="${pageContext.request.contextPath}/news/toNews.html?pageNow=${i}&title=${myPageInfo.title}&csid=${myPageInfo.searchCsid}">
                                            【${i}】 </a>
                                    </c:forEach>
                                    <c:if test="${!myPageInfo.isLastPage}">
                                        <a href="${pageContext.request.contextPath}/news/toNews.html?pageNow=${myPageInfo.pageNum+1}&title=${myPageInfo.title}&csid=${myPageInfo.searchCsid}">
                                            【下一页】 </a>
                                        <a href="${pageContext.request.contextPath}/news/toNews.html?pageNow=${myPageInfo.pages}&title=${myPageInfo.title}&csid=${myPageInfo.searchCsid}">
                                            【末页】 </a>
                                    </c:if>
									</div>
								<c:if test="${!empty myPageInfo.list}">
									<form action="${pageContext.request.contextPath}/news/toNews.html?title=${myPageInfo.title}&csid=${myPageInfo.searchCsid}" method="post">
										<div style="float: right; margin:-50px 10px 0 0; width: 60px; height: 40px">
											<button type="submit" class="btn btn-info btn-fill pull-right">跳转</button>
										</div>
										<div style="float: right; margin:-50px 80px 0 0; width: 60px; height: 40px">
											<input type="number" id="pageNow" class="form-control" placeholder="页面" min="1" max="${myPageInfo.pages}" size=2  name="pageNow">
										</div>

									</form>
								</c:if>

								
							</div>
						</div>






					</div>
				</div>
			</div>


			
<%@include file="./include/footer.jsp"%>
		</div>
	</div>


</body>



<!--  Checkbox, Radio & Switch Plugins -->
<script
	src="${pageContext.request.contextPath}/js/bootstrap-checkbox-radio-switch.js"></script>

<!--  Charts Plugin -->
<script src="${pageContext.request.contextPath}/js/chartist.min.js"></script>

<!--  Notifications Plugin    -->
<script src="${pageContext.request.contextPath}/js/bootstrap-notify.js"></script>


<!-- Light Bootstrap Table Core javascript and methods for Demo purpose -->
<script
	src="${pageContext.request.contextPath}/js/light-bootstrap-dashboard.js"></script>

<!-- Light Bootstrap Table DEMO methods, don't include it in your project! -->
<script src="${pageContext.request.contextPath}/js/demo.js"></script>



</html>